package com.wmobile.utils;

import java.util.List;

import com.wellsoft.mobileoa.R;
import com.wellsoft.mobileoa.utils.BaseActivity;

import android.view.View;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.RadioButton;

public abstract class PopListDialogAdapter<T> extends BaseAdapter {
	protected BaseActivity baseActivity;
	protected List<T> dataList;
	protected List<Integer> selectedIndex;
	protected boolean isMultiSelect;
	protected View.OnClickListener radioButtonClickListener;

	public void setRadioButtonClickListener(
			View.OnClickListener radioButtonClickListener) {
		this.radioButtonClickListener = radioButtonClickListener;
	}

	@Override
	public int getCount() {
		if(dataList == null){
			return 0;
		}else{
			return dataList.size();
		}
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public void updateSelectedView(View childView, int position) {
		if (isMultiSelect) {
			CheckBox itemCb = (CheckBox) childView.findViewById(R.id.itemcb);
			if (selectedIndex.contains(Integer.valueOf(position))) {
				itemCb.setChecked(true);
			} else {
				itemCb.setChecked(false);
			}
		} else {
			RadioButton itemRb = (RadioButton) childView.findViewById(R.id.itemrb);
			if (selectedIndex.contains(Integer.valueOf(position))) {
				itemRb.setChecked(true);
			} else {
				itemRb.setChecked(false);
			}
		}
	}
}
